package com.xiyu.service.repository.fee.recharge;

import com.xiyu.service.model.elder.info.ElderInfoFetcher;
import com.xiyu.service.model.fee.recharge.FeeRechargeFlowFetcher;
import com.xiyu.service.vo.fee.feeRecharge.FeeRechargePageQueryFlowInput;
import com.xiyu.service.model.fee.recharge.FeeRechargeFlow;
import com.xiyu.service.model.fee.recharge.FeeRechargeFlowTable;
import org.babyfish.jimmer.spring.repository.JRepository;
import org.babyfish.jimmer.Page;
import org.springframework.util.StringUtils;

public interface FeeRechargeFlowRepository extends JRepository<FeeRechargeFlow, Long> {
    FeeRechargeFlowTable feeRechargeFlowTable = FeeRechargeFlowTable.$;

    default Page<FeeRechargeFlow> pageQueryFlow(FeeRechargePageQueryFlowInput inputVO){
    return sql().createQuery(feeRechargeFlowTable)
            .whereIf(inputVO.getFeeCategoryId() != null, feeRechargeFlowTable.feeCategoryId().eq(inputVO.getFeeCategoryId()))
            .whereIf(inputVO.getCreateTime() != null, () -> feeRechargeFlowTable.createTime().between(inputVO.getCreateTime()[0], inputVO.getCreateTime()[1]))
            .whereIf(StringUtils.hasText(inputVO.getName()), () -> feeRechargeFlowTable.elder().name().like(inputVO.getName()))
            .orderBy(feeRechargeFlowTable.id().desc())
            .select(feeRechargeFlowTable.fetch(FeeRechargeFlowFetcher.$.allTableFields()
                    .elder(ElderInfoFetcher.$.allTableFields())))
            .fetchPage(inputVO.getPageNo() - 1, inputVO.getPageSize());
    }


}